import {request} from '@/api/service'
import {BUTTON_STATUS_BOOL, BUTTON_WHETHER_BOOL, BUTTON_VALUE_TO_COLOR_MAPPING} from '@/config/button'
import {urlPrefix as menuPrefix} from './api'
import {urlPrefix as buttonPrefix} from '../button/api'
import VFromDesign from '@/components/v-form-design/form-designer/index'
import XEUtils from 'xe-utils'

export const crudOptions = (vm) => {
  return {
    pagination: false,
    pageOptions: {
      compact: true
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false
    },
    rowHandle: {
      view: {
        thin: true,
        text: '',
        disabled() {
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        thin: true,
        text: '',
        disabled() {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '',
        disabled() {
          return !vm.hasPermissions('Delete')
        }
      },
      width: 230
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 80
    },

    viewOptions: {
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 12, // 默认的表单 span
      // type:'drawer',//默认对话框模式，drawer 抽屉模式
      // size: '100%',
      fullscreen: true,
      maxHeight: true,
      draggable:false,
    },
    columns: [
      {
        title: '关键词',
        key: 'search',
        show: false,
        disabled: true,
        search: {
          disabled: false,
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入关键词'
          }
        },
        form: {
          disabled: true,
          component: {
            props: {
              clearable: true
            }
          }
        },
        view: { // 查看对话框组件的单独配置
          disabled: true
        }
      },
      {
        title: 'ID',
        key: 'id',
        show: false,
        width: 60,
        form: {
          component: {
            show: false
          }
        }
      },
      {
        title: '表单名称',
        key: 'name',
        sortable: true,
        search: {
          disabled: false,
          component: {
            props: {
              clearable: true
            }
          }
        },
        type: 'input',
        form: {
          rules: [ // 表单校验规则
            {required: true, message: '表单名称必填项'}
          ],
          component: {
            props: {
              clearable: true
            },
            placeholder: '请输入表单名称'
          },
          itemProps: {
            class: {yxtInput: true}
          }

        }
      },
      {
        key: 'form_design',
        show: false,
        form: {
          component: {
            "name": VFromDesign, span: 24,
            props: {
              designerConfig:{
                resetFormJson: true
              }
            }
          },
          itemProps: {
            labelWidth: '0px' //可以隐藏表单项的label
          }
        }
      },
      {
        title: '状态',
        key: 'enable',
        sortable: true,
        search: {
          disabled: false
        },
        type: 'radio',
        dict: {
          data: BUTTON_STATUS_BOOL
        },
        form: {
          value: true,

          component: {
            placeholder: '请选择状态'
          }
        }
      }
    ].concat(vm.commonEndColumns({show_create_datetime: false, show_datetime: false})),
    formGroup: {
      type: 'collapse', // tab
      accordion: false,
      groups: {
        base: {
          title: '基本信息',
          icon: 'el-icon-postcard',
          columns: ['name', 'enable', 'description', 'dept_belong_id']
        },
        form: {
          title: '表单设计',
          icon: 'el-icon-connection',
          columns: ['form_design']
        }
      }
    }
  }
}
